﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class StaticData
{
    public static List<RoleInfo> listRoleInfo;

    public static List<ItemInfo> listItemInfo;

    public static List<DropInfo> listDropInfo;

    public static List<EquipInfo> listEquipInfo;

    public static List<MissionInfo> listMissionInfo;

    public static void Init()
    {
        TextAsset textAsset = Resources.Load<TextAsset>("Json/RoleInfo");
        if (textAsset != null)
        {
            listRoleInfo = JsonConvert.DeserializeObject<List<RoleInfo>>(textAsset.text);
            Debug.Log("listRoleInfo count=" + listRoleInfo.Count);
        }

        textAsset = Resources.Load<TextAsset>("Json/ItemInfo");
        if (textAsset != null)
        {
            listItemInfo = JsonConvert.DeserializeObject<List<ItemInfo>>(textAsset.text);
        }

        textAsset = Resources.Load<TextAsset>("Json/DropInfo");
        if (textAsset != null)
        {
            listDropInfo = JsonConvert.DeserializeObject<List<DropInfo>>(textAsset.text);
        }

        textAsset = Resources.Load<TextAsset>("Json/EquipInfo");
        if (textAsset != null)
        {
            listEquipInfo = JsonConvert.DeserializeObject<List<EquipInfo>>(textAsset.text);
        }

        textAsset = Resources.Load<TextAsset>("Json/MissionInfo");
        if (textAsset != null)
        {
            listMissionInfo = JsonConvert.DeserializeObject<List<MissionInfo>>(textAsset.text);
        }

    }


    static public RoleInfo GetRoleInfo(string id)
    {
        for (int i = 0; i < listRoleInfo.Count; i++)
        {
            if (listRoleInfo[i].id == id)
            {
                return listRoleInfo[i];
            }
        }

        return null;
    }

    static public DropInfo GetDropInfo(string id)
    {
        for (int i = 0; i < listDropInfo.Count; i++)
        {
            if (listDropInfo[i].id == id)
            {
                return listDropInfo[i];
            }
        }

        return null;
    }

    static public ItemInfo GetItemInfo(string id)
    {
        for (int i = 0; i < listItemInfo.Count; i++)
        {
            if (listItemInfo[i].id == id)
            {
                return listItemInfo[i];
            }
        }
        return null;
    }

    static public EquipInfo GetEquipInfo(string id)
    {
        for (int i = 0; i < listEquipInfo.Count; i++)
        {
            if (listEquipInfo[i].id == id)
            {
                return listEquipInfo[i];
            }
        }
        return null;
    }

    static public MissionInfo GetMissionInfo(string id)
    {
        for (int i = 0; i < listMissionInfo.Count; i++)
        {
            if (listMissionInfo[i].id == id)
            {
                return listMissionInfo[i];
            }
        }
        return null;
    }


    static public string GetMonster(string id)
    {
        for (int i = 0; i < listRoleInfo.Count; i++)
        {
            if (listRoleInfo[i].id == id)
            {
                return listRoleInfo[i].name;
            }
        }
        return null;
    }
}

